package com.rmuti.acm.string;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class CDR1 {

	public static void main(String[] args) {
		try {
			Scanner sc = new Scanner(new File("C:/Users/off/git/rmuti-programming-lab/javapattern/src/test.in"));
			String str = sc.nextLine();
			String[] firstArr = str.split(" ");
			int loop = Integer.parseInt(firstArr[0]);
			int position = Integer.parseInt(firstArr[1]);
			for (int i = 0; i < loop; i++) {
				String line = sc.nextLine();
				String[] lineArr = line.split(" ");
				String output = lineArr[0];
				if (lineArr.length - 1 < position) {
					int counter = 0;
					for (int j = 1; j < lineArr.length; j++) {
						counter += Integer.parseInt(lineArr[j]);
					}
					output += " " + counter;
				} else {
					output += " " + lineArr[position];
				}
				System.out.println(output);
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}
}
